In this Getting Started, we will create a console application running in .NET 6 or 8 that will read a value from an OPC server, and display the value on the console.
Start the IDE (Integrated Development Environment) of your choice.
In this step, we will create a new .NET console application project.
If you are using Visual Studio, select New Project dialog, select Console App. Press the button.
-> -> from the menu. In theIf you are using JetBrains Rider, select New Solution on the Welcome to JetBrains Rider screen. In the New Solution dialog, select Console Application. Verify the Language or change it to C#. Press the button.
In this step, we will add a reference to the OpcLabs.QuickOpc NuGet package.
If you are using Visual Studio, switch to the Solution Explorer window, right-click on the project node (ConsoleAppn), and select command. In the NuGet: project window, switch to the Browse tab, and type OpcLabs.QuickOpc into the search box. Select the OpcLabs.QuickOpc package in the package list in the left pane of the window. In the right pane of the window, verify or change the package version next to the Version label. The version should be "Latest stable 5.81.build" (where build is a build number). Press the button.
If you are using JetBrains Rider, switch to the NuGet window; if it is not visible, use -> -> (Alt+7) command from the menu. In the NuGet window, switch to the Packages tab, and type OpcLabs.QuickOpc into the search box. Select the OpcLabs.QuickOpc package under Available Packages list in the left pane of the window. In the right pane of the window, verify or change the package version next to the Version label. The version should be "5.81.build" (where build is a build number). Press the green button next to the name of your project. Press the button when asked to confirm the installation of the package.
Open the Program.cs file, and add following code to the beginning of the file:
using OpcLabs.EasyOpc.UA;
In Program.cs, replace the body of the Main method by following code:
var client = new EasyUAClient(); object value = client.ReadValue( "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10853"); Console.WriteLine(value); Console.ReadLine();
The program may now look like this in the IDE:
If you are using Visual Studio, select F5) from the menu, or press the corresponding button on the toolbar.
-> (If you are using JetBrains Rider, select F5), or press the corresponding button on the toolbar. When the Edit configuration dialog appears, press the button.
-> (This will build and launch the program. The value will be read from the OPC server and displayed on the console. Press Enter to exit the program.
Start the IDE (Integrated Development Environment) of your choice.
In this step, we will create a new .NET console application project.
If you are using Visual Studio, select New Project dialog, select Console App. Press the button.
-> -> from the menu. In theIf you are using JetBrains Rider, select New Solution on the Welcome to JetBrains Rider screen. In the New Solution dialog, select .NET Core -> Console Application. Verify the Language or change it to C#. Press the button.
In this step, we will add a reference to the OpcLabs.QuickOpc NuGet package.
If you are using Visual Studio, switch to the Solution Explorer window, right-click on the project node (ConsoleAppn), and select command. In the NuGet: project window, switch to the Browse tab, and type OpcLabs.QuickOpc into the search box. Select the OpcLabs.QuickOpc package in the package list in the left pane of the window. In the right pane of the window, verify or change the package version next to the Version label. The version should be "Latest stable 5.81.build" (where build is a build number). Press the button.
If you are using JetBrains Rider, switch to the NuGet window; if it is not visible, use -> -> (Alt+7) command from the menu. In the NuGet window, switch to the Packages tab, and type OpcLabs.QuickOpc into the search box. Select the OpcLabs.QuickOpc package under Available Packages list in the left pane of the window. In the right pane of the window, verify or change the package version next to the Version label. The version should be "5.81.build" (where build is a build number). Press the green button next to the name of your project. Press the button when asked to confirm the installation of the package.
Open the Program.cs file, and add following code to the beginning of the file:
using OpcLabs.EasyOpc.DataAccess;
In Program.cs, replace the body of the Main method by following code:
var client = new EasyDAClient(); object value = client.ReadItemValue( "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Double"); Console.WriteLine(value);
If you are using Visual Studio, select F5) from the menu, or press the corresponding button on the toolbar.
-> (If you are using JetBrains Rider, select F5), or press the corresponding button on the toolbar. When the Edit configuration dialog appears, press the button.
-> (This will build and launch the program. The value will be read from the OPC server and displayed on the console. Press Enter to exit the program.